
#include <BIndexArray>
#include <BPrimitive>
#include "member_BPrimitive.h"

using namespace BWE;

#define member					(*(member_BPrimitive*)_ptr)
#define member_allocate()		_ptr = new member_BPrimitive(this)
#define member_release()		delete (member_BPrimitive*)_ptr

BPrimitive::BPrimitive(Mode mode, int first, int count)
{
	member_allocate();
	member.mode = mode;
	member.first = first;
	member.count = count;
}
BPrimitive::BPrimitive(Mode mode, BIndexArray* indices)
{
	member_allocate();
	member.mode = mode;
	member.first = 0;
	if (indices)
	{
		member.count = indices->size();
		member.indices = indices;
	}
}
BPrimitive::~BPrimitive()
{
	member_release();
}

void BPrimitive::set(Mode mode, int first, int count)
{
	member.mode = mode;
	member.first = first;
	member.count = count;
}

void BPrimitive::setMode(Mode mode)
{
	if (member.mode != mode)
	{
		member.mode = mode;
	}
}
BPrimitive::Mode BPrimitive::mode() const
{
	return member.mode;
}

void BPrimitive::setFirst(int first)
{
	if (member.first != first)
	{
		member.first = first;
		if (member.first < 0)
			member.first = 0;
	}
}
int BPrimitive::first() const
{
	return member.first;
}

void BPrimitive::setCount(int count)
{
	if (member.count != count)
	{
		member.count = count;
		if (member.count < 0)
			member.count = 0;
	}
}
int BPrimitive::count() const
{
	return member.count;
}

void BPrimitive::setIndices(BIndexArray* indices)
{
	member.indices = indices;
}
BIndexArray* BPrimitive::indices() const
{
	return member.indices;
}
